import store from '../store/index'

import * as $utils from '../utils/HHUtil'

import Cookiew from 'js-cookie';
import {Notification} from 'element-ui';

export const checkLogin = function (to, from, next) {
  // console.log(to.path);
  if (to.path === '/login') next();
  if ($utils.hasValue(store.getters.userInfo.username)) {
    next();
  }
  store.dispatch('getUserInfoByToken').then(() => {
    next();
  }).catch((err) => {
    console.log(err);
    // Notification.error({
    //   title: 'Error',
    //   message: 'You must login first!'
    // });
    next({path: "/login"});
  });
};
